using System;
using System.Diagnostics;

namespace CUtil
{
	/// <summary>
	/// Summary description for DateTimeUtil.
	/// </summary>
	public class DateTimeUtil
	{
		#region Fields

		/// <summary>
		/// DateTimeStringCreator
		/// </summary>
		private static DateTimeStringCreator dateTimeStringCreator;

		#endregion

		#region Constructors and Destructors

        public static DateTimeStringCreator MyDateTimeStringCreator
        {
            get
            {
                if (dateTimeStringCreator == null)
                    dateTimeStringCreator = new DateTimeStringCreator();
                return dateTimeStringCreator;

            }
            
        }
		/// <summary>
		/// DateTimeUtil
		/// </summary>
		public DateTimeUtil()
		{
			
		}

		#endregion

		#region Methods

		/// <summary>
		/// GetDateTimeDayFormatString
		/// </summary>
		/// <param name="parDigits"></param>
		/// <returns></returns>
		private string GetDateTimeDayFormatString(int parDigits)
		{
			switch (parDigits)
			{
				case 2: 
				{
					return DateTimeFormatStrings.DayFormatStringTwoDigit;
				}
				default:
				{
					return DateTimeFormatStrings.DayFormatStringNormal;
				}
			}
		}
		/// <summary>
		/// GetDateTimeMonthFormatString
		/// </summary>
		/// <param name="parDigits"></param>
		/// <returns></returns>
		private string GetDateTimeMonthFormatString(int parDigits)
		{
			switch (parDigits)
			{
				case 2: 
				{
					return DateTimeFormatStrings.MonthFormatStringTwoDigit;
				}
				default:
				{
					return DateTimeFormatStrings.MonthFormatStringNormal;
				}
			}
		}
		/// <summary>
		/// GetDateTimeYearFormatString
		/// </summary>
		/// <param name="parDigits"></param>
		/// <returns></returns>
		private string GetDateTimeYearFormatString(int parDigits)
		{
			switch (parDigits)
			{
				case 4: 
				{
					return DateTimeFormatStrings.YearFormatStringFourDigit;
				}
				default:
				{
					return DateTimeFormatStrings.YearFormatStringNormal;
				}
			}
		}
		/// <summary>
		/// CreateDayStringTwoDigit
		/// </summary>
		/// <param name="parDay"></param>
		/// <returns></returns>
		public static string CreateDayStringTwoDigit(DateTime parDateTime)
		{
			try
			{
				string locDayFormat = DateTimeFormatStrings.DayFormatStringTwoDigit;
                return MyDateTimeStringCreator.CreateDayString(parDateTime, locDayFormat);
			}
			catch (Exception exc)
			{
				Debug.WriteLine("Error creating DayString" + exc.Message);
			}
			return null;
		}
		/// <summary>
		/// CreateMonthStringTwoDigit
		/// </summary>
		/// <param name="parDay"></param>
		/// <returns></returns>
        public static string CreateMonthStringTwoDigit(DateTime parDateTime)
		{
			try
			{
				string locMonthFormat = DateTimeFormatStrings.MonthFormatStringTwoDigit;
                return MyDateTimeStringCreator.CreateMonthString(parDateTime, locMonthFormat);
			}
			catch (Exception exc)
			{
				Debug.WriteLine("Error creating MonthString" + exc.Message);
			}
			return null;
		}
		/// <summary>
		/// CreateYearStringFourDigit
		/// </summary>
		/// <param name="parDay"></param>
		/// <returns></returns>
		public static string CreateYearStringFourDigit(DateTime parDateTime)
		{
			try
			{
				string locYearFormat = DateTimeFormatStrings.YearFormatStringFourDigit;
                return MyDateTimeStringCreator.CreateYearString(parDateTime, locYearFormat);
			}
			catch (Exception exc)
			{
				Debug.WriteLine("Error creating YearString" + exc.Message);
			}
			return null;
		}

		#endregion

		#region Class DateTimeFormatStrings

		private class DateTimeFormatStrings
		{

			#region Constants

			// Day Format Strings
			public const string DayFormatStringNormal = "d";
			public const string DayFormatStringTwoDigit = "dd";
			// Month Format Strings
			public const string MonthFormatStringNormal = "M";
			public const string MonthFormatStringTwoDigit = "MM";
			// Year Format Strings
			public const string YearFormatStringNormal = "yy";
			public const string YearFormatStringFourDigit = "yyyy";

			#endregion
		}

		#endregion

		#region Class DateTimeStringCreator

		public class DateTimeStringCreator
		{
			#region Methods Public

			/// <summary>
			/// CreateDayString
			/// </summary>
			/// <param name="parDT"></param>
			/// <param name="parDateTimeDayFormatString"></param>
			/// <returns></returns>
			public string CreateDayString(DateTime parDT,string parDateTimeDayFormatString)
			{
				return parDT.ToString(parDateTimeDayFormatString);
			}

			/// <summary>
			/// CreateMonthString
			/// </summary>
			/// <param name="parDT"></param>
			/// <param name="parDateTimeMonthFormatString"></param>
			/// <returns></returns>
			public string CreateMonthString(DateTime parDT,string parDateTimeMonthFormatString)
			{
				return parDT.ToString(parDateTimeMonthFormatString);
			}

			/// <summary>
			/// CreateYearString
			/// </summary>
			/// <param name="parDT"></param>
			/// <param name="parCDateTimeYearFormatString"></param>
			/// <returns></returns>
			public string CreateYearString(DateTime parDT,string parDateTimeYearFormatString)
			{
				return  parDT.ToString(parDateTimeYearFormatString);
			}

			#endregion
		}

		#endregion
	}
}
